package com.thread.start;

/**
 * 线程停止
 *
 * @author jiangbang
 * @date 2016/6/16
 */
public class Demo01 {
    public static void main(String[] args) {
        Study study = new Study();
        new Thread(study).start();
        //外部干涉
        for(int i=0;i<100;i++){
            if(50==i){
                study.stop();
            }
        }
    }
}


class Study implements Runnable{
    //线程类中定义线程体使用的标识
    private boolean flag = true;

    @Override
    public void run() {
        //线程体使用该标识
        while (flag){
            System.out.println("study thread ...");
        }
    }

    public void stop() {
        this.flag = false;
    }
}